package display;

import hardware.Display2D;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;



/**
 * 
 * 
 *
 * @author Tavin
 * @version 1.0
 */

public class Canvas_Display extends Canvas{

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
public static final int CellSize = 46;	
public static final int CellXCount = 8;
public static final int CellYCount = 8;
public static final int CellMargin =1;

private RGBColor  [] [] displayArea;	



public Canvas_Display(RGBColor  [] [] newDisplayArea)
{
displayArea=newDisplayArea;
}



public void update (Graphics MyGraphics) 
{
	drawDisplay (MyGraphics);
	drawPixels(MyGraphics);  
}


public void paint (Graphics MyGraphics) 
{
	drawDisplay (MyGraphics);
	drawPixels(MyGraphics);  
}




public void drawDisplay (Graphics MyGraphics) 
{
	int xCounter;
	int yCounter;	
	
	MyGraphics.setColor(Color.DARK_GRAY);
	for (xCounter=0;xCounter<CellXCount;xCounter++)
		{
		for (yCounter=0;yCounter<CellYCount;yCounter++)
			{
			MyGraphics.drawRect((xCounter*CellSize), (yCounter*CellSize),CellSize,CellSize);
			}
		}
	MyGraphics.setColor(Color.black);
	for (xCounter=0;xCounter<CellXCount;xCounter++)
			{
			for (yCounter=0;yCounter<CellYCount;yCounter++)
			{
				MyGraphics.fillRect((xCounter*CellSize)+CellMargin, (yCounter*CellSize)+CellMargin,CellSize-(2*CellMargin),CellSize-(2*CellMargin));
			}
		}
	
	  
	}






//public void update(Graphics MyGraphics)
public void drawPixels (Graphics MyGraphics) 
{

	
	int xCounter;
	int yCounter;
	

	if (MyGraphics==null)
		return;
	
	MyGraphics.setColor(Color.DARK_GRAY);
	for (xCounter=0;xCounter<CellXCount;xCounter++)
		{
		for (yCounter=0;yCounter<CellYCount;yCounter++)
		{
			MyGraphics.setColor(displayArea[xCounter] [Display2D.getRowCount()-1-yCounter].GetColor());	
			MyGraphics.fillOval((xCounter*CellSize)+CellMargin, (yCounter*CellSize)+CellMargin,CellSize-(2*CellMargin),CellSize-(2*CellMargin));
		}
	}

	// 

}
}
